{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lab 26 - Permutation tests\n",
"\n",
"In Lab 5 we looked used confidence intervals to compare the means of two groups to determine if they were different. In this lab, we'll use hypothesis testing to compare the means.\n",
"\n",
"First, we'll download the green taxi trip data for Dec. 5, 2018.\n",
"\n",
"The NYC Open Data datast of all 2018 green taxi trips is here: [https://data.cityofnewyork.us/Transportation/2018-Green-Taxi-Trip-Data/w7fs-fd9i](https://data.cityofnewyork.us/Transportation/2018-Green-Taxi-Trip-Data/w7fs-fd9i)\n",
"\n",
"The dataset contains almost 9 million rows, so we will filter the data to only be trips from Dec. 5, 2018 to make the dataset smaller. To do this:\n",
"- Click on the \"Filter\" button.\n",
"- On the menu that appear, click on \"Add a New Filter Condition\".\n",
"- Choose \"lpep_pickup_datetime\" but change the \"is\" to be \"is between\".\n",
"- Click in the box below and a calendar will pop up. Highlight December 5, 2018.\n",
"- Click the second box below and a calendar will pop up. Highlight December 6, 2018.\n",
"- It will take a few seconds (it's a large file) but the rows on the left will be filtered to be all trips with pickups between Dec. 5 2018 at 12am and Dec. 6 2018 at 12am, or all counts with pickups on Dec. 5.\n",
"\n",
"To download the file,\n",
"- Click on the \"Export\" button.\n",
"- Under \"Download\", choose \"CSV\".\n",
"- The download will begin automatically (files are usually stored in \"Downloads\" folder).\n",
"\n",
"First, let's import the necessary libraries."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Comparing mean trip distances with 1 or more than 1 passengers\n",
"\n",
"Is there a different in the mean trip distance for trips taken with only 1 passenger and trips taken with more than 1 passengers?\n",
"\n",
"We will test this hypothesis.\n",
"\n",
"#### Hypothesis testing step 1\n",
"\n",
"Null hypothesis: The mean trip distance for trips with only 1 passenger is the same as the mean trip distance for trips with 2 or more passengers.\n",
"\n",
"Alternative hypothesis: The mean trip distance for trips with only 1 passenger is different than the mean trip distance for trips with 2 or more passengers.\n",
"\n",
"Before proceeding further, load the green taxi trip data into the dataframe `taxi`."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
VendorID
\n",
"
lpep_pickup_datetime
\n",
"
lpep_dropoff_datetime
\n",
"
store_and_fwd_flag
\n",
"
RatecodeID
\n",
"
PULocationID
\n",
"
DOLocationID
\n",
"
passenger_count
\n",
"
trip_distance
\n",
"
fare_amount
\n",
"
extra
\n",
"
mta_tax
\n",
"
tip_amount
\n",
"
tolls_amount
\n",
"
ehail_fee
\n",
"
improvement_surcharge
\n",
"
total_amount
\n",
"
payment_type
\n",
"
trip_type
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
2
\n",
"
12/05/2018 12:00:00 AM
\n",
"
12/05/2018 12:16:37 AM
\n",
"
N
\n",
"
1
\n",
"
74
\n",
"
129
\n",
"
1
\n",
"
6.13
\n",
"
19.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
5.76
\n",
"
NaN
\n",
"
0.3
\n",
"
26.56
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
1
\n",
"
2
\n",
"
12/05/2018 12:00:00 AM
\n",
"
12/05/2018 12:00:00 AM
\n",
"
N
\n",
"
1
\n",
"
7
\n",
"
179
\n",
"
1
\n",
"
7.71
\n",
"
25.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
26.80
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
2
\n",
"
2
\n",
"
12/05/2018 12:00:08 AM
\n",
"
12/05/2018 12:05:45 AM
\n",
"
N
\n",
"
1
\n",
"
41
\n",
"
74
\n",
"
2
\n",
"
1.18
\n",
"
6.0
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
7.30
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
3
\n",
"
2
\n",
"
12/05/2018 12:00:14 AM
\n",
"
12/05/2018 12:05:17 AM
\n",
"
N
\n",
"
1
\n",
"
255
\n",
"
112
\n",
"
1
\n",
"
0.98
\n",
"
5.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
6.80
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
4
\n",
"
2
\n",
"
12/05/2018 12:00:25 AM
\n",
"
12/05/2018 12:05:36 AM
\n",
"
N
\n",
"
1
\n",
"
256
\n",
"
112
\n",
"
1
\n",
"
1.51
\n",
"
6.5
\n",
"
0.5
\n",
"
0.5
\n",
"
1.56
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
9.36
\n",
"
1
\n",
"
1
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" VendorID lpep_pickup_datetime lpep_dropoff_datetime \\\n",
"0 2 12/05/2018 12:00:00 AM 12/05/2018 12:16:37 AM \n",
"1 2 12/05/2018 12:00:00 AM 12/05/2018 12:00:00 AM \n",
"2 2 12/05/2018 12:00:08 AM 12/05/2018 12:05:45 AM \n",
"3 2 12/05/2018 12:00:14 AM 12/05/2018 12:05:17 AM \n",
"4 2 12/05/2018 12:00:25 AM 12/05/2018 12:05:36 AM \n",
"\n",
" store_and_fwd_flag RatecodeID PULocationID DOLocationID passenger_count \\\n",
"0 N 1 74 129 1 \n",
"1 N 1 7 179 1 \n",
"2 N 1 41 74 2 \n",
"3 N 1 255 112 1 \n",
"4 N 1 256 112 1 \n",
"\n",
" trip_distance fare_amount extra mta_tax tip_amount tolls_amount \\\n",
"0 6.13 19.5 0.5 0.5 0.00 5.76 \n",
"1 7.71 25.5 0.5 0.5 0.00 0.00 \n",
"2 1.18 6.0 0.5 0.5 0.00 0.00 \n",
"3 0.98 5.5 0.5 0.5 0.00 0.00 \n",
"4 1.51 6.5 0.5 0.5 1.56 0.00 \n",
"\n",
" ehail_fee improvement_surcharge total_amount payment_type trip_type \n",
"0 NaN 0.3 26.56 2 1 \n",
"1 NaN 0.3 26.80 2 1 \n",
"2 NaN 0.3 7.30 2 1 \n",
"3 NaN 0.3 6.80 2 1 \n",
"4 NaN 0.3 9.36 1 1 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"taxi = pd.read_csv(\"Dec5_2018_Green_Taxi_Trip_Data.csv\")\n",
"taxi.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hypothesis testing step 2\n",
"\n",
"Our test statistic will be the difference in mean trip distance between trips with only 1 passenger and trips with 2 or more passengers. To calculate the test statistic for the data:\n",
"\n",
"1. Compute the mean trip distance when there is only 1 passenger.\n",
"2. Compute the mean trip distance when there are 2 or more passengers.\n",
"3. Subtract mean 1 from mean 2 and take the absolute value.\n",
"\n",
"Let's do step 1: compute the mean trip distance when there is only 1 passenger.\n",
"\n",
"Hint:\n",
"a. Use a filter to create a new dataframe containing only trips with 1 passenger. \n",
"b. Compute the mean trip distance in the new dataframe.\n",
""
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.5752665518090083"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"one_pass_filter = taxi[\"passenger_count\"] == 1\n",
"one_pass_taxi = taxi[one_pass_filter]\n",
"one_mean = one_pass_taxi[\"trip_distance\"].mean()\n",
"one_mean"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Step 2: Compute the mean trip distance when there are 2 or more passengers."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.274248217757614"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"multi_pass_taxi = taxi[taxi[\"passenger_count\"] >= 2]\n",
"multi_mean = multi_pass_taxi[\"trip_distance\"].mean()\n",
"multi_mean"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Step 3: Subtract mean 1 from mean 2 and take the absolute value.\n",
"\n",
"This value is the test statistic for our data."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3010183340513941"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.abs(one_mean - multi_mean)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hypothesis testing step 3\n",
"Step 3 is to simulate the test statistic assuming the null hypothesis is true.\n",
"\n",
"We will do this by permuting (randomly changing) the passenger count data in the dataframe, without changing any other columns. If the passenger count doesn't matter, then switching it around shouldn't change the difference in means. \n",
"\n",
"First let's make a new dataframe called `permuted_taxi` by loading the data from the CSV file again."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
VendorID
\n",
"
lpep_pickup_datetime
\n",
"
lpep_dropoff_datetime
\n",
"
store_and_fwd_flag
\n",
"
RatecodeID
\n",
"
PULocationID
\n",
"
DOLocationID
\n",
"
passenger_count
\n",
"
trip_distance
\n",
"
fare_amount
\n",
"
extra
\n",
"
mta_tax
\n",
"
tip_amount
\n",
"
tolls_amount
\n",
"
ehail_fee
\n",
"
improvement_surcharge
\n",
"
total_amount
\n",
"
payment_type
\n",
"
trip_type
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
2
\n",
"
12/05/2018 12:00:00 AM
\n",
"
12/05/2018 12:16:37 AM
\n",
"
N
\n",
"
1
\n",
"
74
\n",
"
129
\n",
"
1
\n",
"
6.13
\n",
"
19.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
5.76
\n",
"
NaN
\n",
"
0.3
\n",
"
26.56
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
1
\n",
"
2
\n",
"
12/05/2018 12:00:00 AM
\n",
"
12/05/2018 12:00:00 AM
\n",
"
N
\n",
"
1
\n",
"
7
\n",
"
179
\n",
"
1
\n",
"
7.71
\n",
"
25.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
26.80
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
2
\n",
"
2
\n",
"
12/05/2018 12:00:08 AM
\n",
"
12/05/2018 12:05:45 AM
\n",
"
N
\n",
"
1
\n",
"
41
\n",
"
74
\n",
"
2
\n",
"
1.18
\n",
"
6.0
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
7.30
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
3
\n",
"
2
\n",
"
12/05/2018 12:00:14 AM
\n",
"
12/05/2018 12:05:17 AM
\n",
"
N
\n",
"
1
\n",
"
255
\n",
"
112
\n",
"
1
\n",
"
0.98
\n",
"
5.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
6.80
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
4
\n",
"
2
\n",
"
12/05/2018 12:00:25 AM
\n",
"
12/05/2018 12:05:36 AM
\n",
"
N
\n",
"
1
\n",
"
256
\n",
"
112
\n",
"
1
\n",
"
1.51
\n",
"
6.5
\n",
"
0.5
\n",
"
0.5
\n",
"
1.56
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
9.36
\n",
"
1
\n",
"
1
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" VendorID lpep_pickup_datetime lpep_dropoff_datetime \\\n",
"0 2 12/05/2018 12:00:00 AM 12/05/2018 12:16:37 AM \n",
"1 2 12/05/2018 12:00:00 AM 12/05/2018 12:00:00 AM \n",
"2 2 12/05/2018 12:00:08 AM 12/05/2018 12:05:45 AM \n",
"3 2 12/05/2018 12:00:14 AM 12/05/2018 12:05:17 AM \n",
"4 2 12/05/2018 12:00:25 AM 12/05/2018 12:05:36 AM \n",
"\n",
" store_and_fwd_flag RatecodeID PULocationID DOLocationID passenger_count \\\n",
"0 N 1 74 129 1 \n",
"1 N 1 7 179 1 \n",
"2 N 1 41 74 2 \n",
"3 N 1 255 112 1 \n",
"4 N 1 256 112 1 \n",
"\n",
" trip_distance fare_amount extra mta_tax tip_amount tolls_amount \\\n",
"0 6.13 19.5 0.5 0.5 0.00 5.76 \n",
"1 7.71 25.5 0.5 0.5 0.00 0.00 \n",
"2 1.18 6.0 0.5 0.5 0.00 0.00 \n",
"3 0.98 5.5 0.5 0.5 0.00 0.00 \n",
"4 1.51 6.5 0.5 0.5 1.56 0.00 \n",
"\n",
" ehail_fee improvement_surcharge total_amount payment_type trip_type \n",
"0 NaN 0.3 26.56 2 1 \n",
"1 NaN 0.3 26.80 2 1 \n",
"2 NaN 0.3 7.30 2 1 \n",
"3 NaN 0.3 6.80 2 1 \n",
"4 NaN 0.3 9.36 1 1 "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"permuted_taxi = pd.read_csv(\"Dec5_2018_Green_Taxi_Trip_Data.csv\")\n",
"permuted_taxi.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following code will permute the `passenger_count` column and then display the new dataframe:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
VendorID
\n",
"
lpep_pickup_datetime
\n",
"
lpep_dropoff_datetime
\n",
"
store_and_fwd_flag
\n",
"
RatecodeID
\n",
"
PULocationID
\n",
"
DOLocationID
\n",
"
passenger_count
\n",
"
trip_distance
\n",
"
fare_amount
\n",
"
extra
\n",
"
mta_tax
\n",
"
tip_amount
\n",
"
tolls_amount
\n",
"
ehail_fee
\n",
"
improvement_surcharge
\n",
"
total_amount
\n",
"
payment_type
\n",
"
trip_type
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
2
\n",
"
12/05/2018 12:00:00 AM
\n",
"
12/05/2018 12:16:37 AM
\n",
"
N
\n",
"
1
\n",
"
74
\n",
"
129
\n",
"
1
\n",
"
6.13
\n",
"
19.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
5.76
\n",
"
NaN
\n",
"
0.3
\n",
"
26.56
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
1
\n",
"
2
\n",
"
12/05/2018 12:00:00 AM
\n",
"
12/05/2018 12:00:00 AM
\n",
"
N
\n",
"
1
\n",
"
7
\n",
"
179
\n",
"
1
\n",
"
7.71
\n",
"
25.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
26.80
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
2
\n",
"
2
\n",
"
12/05/2018 12:00:08 AM
\n",
"
12/05/2018 12:05:45 AM
\n",
"
N
\n",
"
1
\n",
"
41
\n",
"
74
\n",
"
1
\n",
"
1.18
\n",
"
6.0
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
7.30
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
3
\n",
"
2
\n",
"
12/05/2018 12:00:14 AM
\n",
"
12/05/2018 12:05:17 AM
\n",
"
N
\n",
"
1
\n",
"
255
\n",
"
112
\n",
"
1
\n",
"
0.98
\n",
"
5.5
\n",
"
0.5
\n",
"
0.5
\n",
"
0.00
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
6.80
\n",
"
2
\n",
"
1
\n",
"
\n",
"
\n",
"
4
\n",
"
2
\n",
"
12/05/2018 12:00:25 AM
\n",
"
12/05/2018 12:05:36 AM
\n",
"
N
\n",
"
1
\n",
"
256
\n",
"
112
\n",
"
1
\n",
"
1.51
\n",
"
6.5
\n",
"
0.5
\n",
"
0.5
\n",
"
1.56
\n",
"
0.00
\n",
"
NaN
\n",
"
0.3
\n",
"
9.36
\n",
"
1
\n",
"
1
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" VendorID lpep_pickup_datetime lpep_dropoff_datetime \\\n",
"0 2 12/05/2018 12:00:00 AM 12/05/2018 12:16:37 AM \n",
"1 2 12/05/2018 12:00:00 AM 12/05/2018 12:00:00 AM \n",
"2 2 12/05/2018 12:00:08 AM 12/05/2018 12:05:45 AM \n",
"3 2 12/05/2018 12:00:14 AM 12/05/2018 12:05:17 AM \n",
"4 2 12/05/2018 12:00:25 AM 12/05/2018 12:05:36 AM \n",
"\n",
" store_and_fwd_flag RatecodeID PULocationID DOLocationID passenger_count \\\n",
"0 N 1 74 129 1 \n",
"1 N 1 7 179 1 \n",
"2 N 1 41 74 1 \n",
"3 N 1 255 112 1 \n",
"4 N 1 256 112 1 \n",
"\n",
" trip_distance fare_amount extra mta_tax tip_amount tolls_amount \\\n",
"0 6.13 19.5 0.5 0.5 0.00 5.76 \n",
"1 7.71 25.5 0.5 0.5 0.00 0.00 \n",
"2 1.18 6.0 0.5 0.5 0.00 0.00 \n",
"3 0.98 5.5 0.5 0.5 0.00 0.00 \n",
"4 1.51 6.5 0.5 0.5 1.56 0.00 \n",
"\n",
" ehail_fee improvement_surcharge total_amount payment_type trip_type \n",
"0 NaN 0.3 26.56 2 1 \n",
"1 NaN 0.3 26.80 2 1 \n",
"2 NaN 0.3 7.30 2 1 \n",
"3 NaN 0.3 6.80 2 1 \n",
"4 NaN 0.3 9.36 1 1 "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"permuted_taxi['passenger_count'] = np.random.permutation(permuted_taxi['passenger_count'])\n",
"permuted_taxi.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compare the first few rows of `permuted_taxi` with the first few rows of `taxi`. Some of the `passenger_count` values should have changed.\n",
"\n",
"Compute the difference between mean trip distance with 1 passenger and the mean trip distance with 2 or more passengers using the `permuted_taxi` dataframe. "
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.04632190935092462"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"one_pass_filter = permuted_taxi[\"passenger_count\"] == 1\n",
"one_pass_taxi = permuted_taxi[one_pass_filter]\n",
"one_mean = one_pass_taxi[\"trip_distance\"].mean()\n",
"\n",
"multi_pass_taxi = permuted_taxi[permuted_taxi[\"passenger_count\"] >= 2]\n",
"multi_mean = multi_pass_taxi[\"trip_distance\"].mean()\n",
"\n",
"np.abs(one_mean - multi_mean)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's repeat these steps (permuting the `passenger_count` column and computing the difference between the two means in the permuted dataframe) many times, storing the mean differences is a list.\n",
"\n",
"Remember, use a small number of iterations to test your code, so it is faster."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"mean_diffs = []\n",
"for i in range(1000):\n",
" permuted_taxi['passenger_count'] = np.random.permutation(permuted_taxi['passenger_count'])\n",
" \n",
" one_pass_filter = permuted_taxi[\"passenger_count\"] == 1\n",
" one_pass_taxi = permuted_taxi[one_pass_filter]\n",
" one_mean = one_pass_taxi[\"trip_distance\"].mean()\n",
"\n",
" multi_pass_taxi = permuted_taxi[permuted_taxi[\"passenger_count\"] >= 2]\n",
" multi_mean = multi_pass_taxi[\"trip_distance\"].mean()\n",
"\n",
" diff = np.abs(one_mean - multi_mean)\n",
" mean_diffs.append(diff)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hint:\n",
"The pseudo-code is:\n",
"\n",
"create an empty list\n",
"loop 10,000 times:\n",
" randomly permute the passenger cout column\n",
" compute the mean trip distance for trips with only 1 passenger\n",
" compute the mean trip distance for trips with 2 or more passengers\n",
" compute the difference between the two means\n",
" store the difference in your list\n",
"\n",
"\n",
"\n",
"Graph the histogram of the differences in means that you computed assuming the null hypothesis is true."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAEvpJREFUeJzt3X+QXWV9x/H3t0SRspYfgjtpSF2cxs4EU1G2SGt/7Epbfo0Gp5aBUg1KJ7bFqR3zR6O2o61lJu00OhUtNg4OsaYuFLXJCNjByOr4B2KCkRAoJUAYksFkJCG4SOksfvvHPtFLSHLv3h977z6+XzN39pznPOec55uz+ezZc869G5mJJKleP9fvAUiSesugl6TKGfSSVDmDXpIqZ9BLUuUMekmqnEEvSZUz6CWpcga9JFVuQb8HAHDaaaflyMhIW+s+88wznHjiid0dUJ/UUkstdUA9tdRSB9RTSzfq2Lp16w8y8/Rm/QYi6EdGRtiyZUtb605OTjI2NtbdAfVJLbXUUgfUU0stdUA9tXSjjoh4rJV+XrqRpMoZ9JJUOYNekipn0EtS5Qx6SaqcQS9JlTPoJalyBr0kVc6gl6TKDcQ7Yzuxfc9Brlp9a1/2vWvNJX3ZryTNhmf0klS5pkEfES+LiLsj4nsRsSMi/ra0nxkR346InRFxU0S8tLQfX+Z3luUjvS1BknQsrZzRPwe8OTNfB5wNXBgR5wH/AHw8M38ZOABcXfpfDRwo7R8v/SRJfdI06HPGVJl9SXkl8GbgltK+Hri0TC8v85Tl50dEdG3EkqRZaekafUQcFxHbgH3AHcDDwFOZOV267AYWlelFwOMAZflB4BXdH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